<!--
  File Name: LeaveFormView.php
  Version 1.0
  O1-31-2011
-->


<?php
require_once('LeaveFormController.php');
require_once('functions.php');

class LeaveFormView
{

	public function displayAddLeave($employeeNumber, $gender){
?>

	<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
	<title>Leave App Home</title>
	<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js" type="text/javascript"></script>
	<script src="jquery.js"></script>		
	<script type="text/javascript">
		function undertimeIsSelected()
		{
			var hoursPrompt = "";
			var	minutesPrompt = "";
			var x;
			var y;
			if (document.getElementById('typeOfLeave').value == 'UNDERTIME'  || document.getElementById('typeOfLeave').value == 'TARDINESS') {
				do{									
					x = prompt('Input Hours '+hoursPrompt);
					if(parseInt(x)>12){
						hoursPrompt = ": Maximum hours is 12 hours.";	
					}
					else {										
						if (parseInt(x)<0) {
							hoursPrompt = ": Invalid hours.";										
						} if (x==" " || x=="") {
							x=0;
						} else {
							hoursPrompt = "";										
						}										
					}
				}while(isNaN(x) || parseInt(x)>12 || parseInt(x)<0);
				do{
					y = prompt('Input Minutes '+minutesPrompt);
					if(parseInt(y)>60){
						minutesPrompt = ": Maximum minutes is 60 minutes.";										
					}
					else {
						if (parseInt(y)<0) {
							minutesPrompt = ": Invalid minutes.";										
						} if(y==" " || y=="") {
							y=0;
						} else {
							minutesPrompt = "";										
						}
					}
				}while(isNaN(y) || y>60 || y<0);
				if(x==false && y==false){
					document.getElementById('time').value="";
				}
				else{
					var days = (parseInt(60*x) + parseInt(y))/1440;
					document.getElementById('days').value = days;
					var d = parseInt(x) + '/' + parseInt(y);
					document.getElementById('time').value=d;
				}
				
				
			} else { document.getElementById('time').value=''; }
		}
	</script>				
	<script>
		function registerpage(){
			window.location = "register.php";
		}		
			
		var timeout = 500;
		var closetimer = 0;
		var ddmenuitem = 0;

		function jsddm_open()
		{  jsddm_canceltimer();
		   jsddm_close();
		   ddmenuitem = $(this).find('ul').css('visibility', 'visible');}

		function jsddm_close()
		{  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

		function jsddm_timer()
		{  closetimer = window.setTimeout(jsddm_close, timeout);}

		function jsddm_canceltimer()
		{  if(closetimer)
		   {  window.clearTimeout(closetimer);
			  closetimer = null;}}

		$(document).ready(function()
		{  $('#jsddm > li').bind('mouseover', jsddm_open)
		   $('#jsddm > li').bind('mouseout',  jsddm_timer)});

		document.onclick = jsddm_close;			
		
		$(document).ready(function(){
							   
		   $("a").css({
			'text-decoration':'none',
		   });
		   $("a").hover(function () {
				$(this).css({'text-decoration':'none','font-weight':'bold'});
			  }, function () {
				var cssObj = {
				  'text-decoration':'none',
				  'font-weight':''
				}
				$(this).css(cssObj);
			  });
									   
		   $("#submit").css({
				'background-color':'white',
				'color':'#2F2825'
			});
			$("#submit").hover(function () {
				$(this).css({'background-color' : '#993333','color':'white','font-weight':'bold'});
			  }, function () {
				var cssObj = {
				  'background-color' : 'white',
				  'color' : '#2F2825',
				  'font-weight':''
				}
				$(this).css(cssObj);
			  });				  
				 
		 });
	</script>
			<link href="template.css" rel="stylesheet" type="text/css" media="screen" />
	</head>
	<body>
	<!-- start header -->
	<div id="header">
		<div id="logo">
			<h1><span>UPLB</span> &nbsp; Leave Application</h1>
			<ul id="jsddm">
				<?php if(isset($_SESSION['login']) && $_SESSION['login']==true) {?>
				<li><a href="#">ACTIONS <span>&#x25BC</span></a>
					<ul>
						<li><a href="AddEmployee.php">Add Employee</a></li>
						<li><a href="searchEmployee.php">Change Employee</a></li>
					</ul>
				</li>
				<li><a href="logout.php">LOG OUT</a>
				</li>
				<?php } ?>
			</ul>
		</div>
	</div>
	<!-- end header -->
	<div id="wrapper">
		<!-- start page -->
		<div id="page">
		<div id="page-bg">
			<div id="sidebar1" class="sidebar">			
			</div>
			<!-- start content -->
			<div id="content">
				<div class="post">				
					<div class="entry">
<?php		
	if (isset($_SESSION['username'])) {
		$username = $_SESSION['username'];
?>							
						<form name='addLeave' id='addLeave' method='post' action='validateAdd.php'>
							<table>			
								<tr>						
									<td class='label'>Date of Filing <font size='1'>(mm/dd/yyyy)</font></td>
									<td>
										<input type='text' name='dateOfFiling'id='dateOfFiling'maxlength='10'/>
									</td>
								</tr>
								<tr>
									<td class='label'>Date Received <font size='1'>(mm/dd/yyyy)</font></td>
									<td>
										<input type='text' name='dateReceived' id='dateReceived'maxlength='10'/>
									</td>
								</tr>
								<tr>
									<td class='label'>Type of Leave<font size='1'>&nbsp;&nbsp;</font></td>
									<td>
										<select name='typeOfLeave' id='typeOfLeave' onChange='undertimeIsSelected()'>
											<option name='null' value='null'>[Select Type]</option>
											<option name='SICK_LEAVE' value='SICK_LEAVE'  >Sick Leave</option>
											<option name='VACATION_LEAVE' value='VACATION_LEAVE'  >Vacation Leave</option>
											<option name='AWOL' value='AWOL'  >Absence Without Leave</option>
											<option name='COMPENSATORY' value='COMPENSATORY'  >Compensatory</option>
											<option name='FORCED' value='FORCED'  >Forced Leave</option>
											<option name='MONET_SL' value='MONET_SL'  >Monetization(SL)</option>
											<option name='MONET_VL' value='MONET_VL'  >Monetization(VL)</option>
											<option name='PARENTAL' value='PARENTAL'  >Parental Leave</option>
											<option name='REHABILITATION' value='REHABILITATION'  >Rehabilitation</option>
											<option name='RE-ENERGIZING' value='RE-ENERGIZING'  >Re-energizing</option>
											<option name='SPECIAL' value='SPECIAL'  >Special Leave</option>
											<option name='SUSPENSION' value='SUSPENSION'  >Suspension</option>
											<option name='TARDINESS' value='TARDINESS'>Tardiness</option>
											<option name='UNDERTIME' value='UNDERTIME'>Undertime</option>";
						<?php					
								if ($_SESSION['gender'] == "Male") echo "<option name='PATERNAL' value='PATERNAL'>Paternal</option>";
								if ($_SESSION['gender'] == "Female") echo "<option name='MATERNAL' value='MATERNAL'>Maternal</option>";
						?>		
								
										</select>
									</td>
								</tr>
								<tr>
									<td class='label'>Days<font size='1'>&nbsp;&nbsp;</font></td>
									<td>
										<input type='text' name='days' id='days' maxlength='2'/>
									</td>
								</tr>
								<tr>
									<td class='label'>Start Date <font size='1'>(mm/dd/yyyy)</font></td>
									<td>
										<input type='text' name='startDate' id='startDate'maxlength='10'/>
									</td>
								</tr>
								<tr>
									<td class='label'>End Date <font size='1'>(mm/dd/yyyy)</font></td>
									<td>
										<input type='text' name='endDate' id='endDate'maxlength='10'/>
									</td>
								</tr>
								<tr>
									<td class='label'>Status<font size='1'>&nbsp;&nbsp;</font></td>
									<td>
										<select name='status' id='status'>
											<option name='null' value='null'>[Select Type]</option>
											<option name='WITH_PAY' value='WITH_PAY'>Approved With Pay</option>
											<option name='WITHOUT_PAY' value='WITHOUT_PAY'>Approved Without Pay
											</option>
										</select>
									</td>
								</tr>
								<tr>
									<td>
										<input type='hidden' name='employeeNumber' id='employeeNumber' value="<?php echo $employeeNumber;?>">
									</td>
									<td>
										<input type='hidden' name='time' id='time' value=''/>
									</td>
								</tr>
							</table>
							<input type='submit' name='AddLeave'/>
						</form>
<?php						
	} ?>				<p class="links"><a href='menu.php' class="more">&laquo;&laquo;&nbsp;&nbsp;Home&nbsp;&nbsp;&raquo;&raquo;</a></p>					
					</div>
				</div>
			</div>
			<!-- end content -->
			<!-- start sidebars -->
			<div id="sidebar2" class="sidebar">
			</div>
			<!-- end sidebars -->
			<div style="clear: both;">&nbsp;</div>
		</div>
		</div>
		<!-- end page -->
	</div>
	<div id="footer">	
	</div>
	</body>
</html>

<?php		
	}	
	
	public function requestAddLeave($dateOfFiling, $dateReceived,
									$typeOfLeave, $days, $startDate, $endDate,
									$status, $employeeNumber, $time){
		LeaveFormController::addLeaveForm($dateOfFiling,
										  $dateReceived, $typeOfLeave, $days,
										  $startDate, $endDate,	$status,
										  $employeeNumber, $time);
		return true;
	}
		
	public function showMessage($flag){
			
			if($flag==1){
				//echo "Successful.<br/>";
				//back button to leave form
			} else if ($flag==2) {
				//echo "Changes saved! <br />";
			} else if ($flag==3){
				echo "An error was encountered. Try again.<br/>";				
			}
		
		return 1;
		
	}

	public function requestLeaveList($employeeNumber) {	
		
		LeaveFormController :: generateLeaveList($employeeNumber);
		return 1;
	}
	
	public function showLeaveList($r1, $employeeNumber) {
		
		$ctr = 0;
		$link = makeSQLconnection();
		$q = sprintf("SELECT * from `Employee` where Employee_number = '$employeeNumber'");
		$r = mysql_query($q, $link);
		$data = mysql_fetch_assoc($r);
		$gender = $data['Employee_gender'];
		mysql_close($link);
	?>	
		<html>			
			<head>
			<link href="template.css" rel="stylesheet" type="text/css" media="screen" />
			<title>Edit Leave Form</title>
			<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js' type='text/javascript'></script>
			<script src='jquery.js'></script>
			<script language='javascript'>
				function undertimeIsSelected(ctr)
				{
					var typeOfLeave = "typeOfLeave"+ctr;
					if (document.getElementById(typeOfLeave).value == 'UNDERTIME'  || document.getElementById(typeOfLeave).value == 'TARDINESS') {
						do{
							var x = prompt('Input Hours', 'hours');
						}while(isNaN(x));
						if(x != null){
							do{
								var y = prompt('Input Minutes', 'minutes');
							}while(isNaN(y));
							if(y != null){
								var days = (parseInt(60*x) + parseInt(y))/1440;
								if(isNaN(days)) document.getElementById('days').value = '';
								else {
									var days2 = 'days' + ctr;
									var time = 'time' + ctr;
									document.getElementById(days2).value = days;
									var d = parseInt(x) + '/' + parseInt(y);
									document.getElementById(time).value=d;
									
								}
							}
						}
					} else { 
						var time = 'time' + ctr;
						document.getElementById(time).value=''; 
					}
				}
			</script>
			<script>
				var timeout = 500;
				var closetimer = 0;
				var ddmenuitem = 0;

				function jsddm_open()
				{  jsddm_canceltimer();
				   jsddm_close();
				   ddmenuitem = $(this).find('ul').css('visibility', 'visible');}

				function jsddm_close()
				{  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

				function jsddm_timer()
				{  closetimer = window.setTimeout(jsddm_close, timeout);}

				function jsddm_canceltimer()
				{  if(closetimer)
				   {  window.clearTimeout(closetimer);
					  closetimer = null;}}

				$(document).ready(function()
				{  $('#jsddm > li').bind('mouseover', jsddm_open)
				   $('#jsddm > li').bind('mouseout',  jsddm_timer)});

				document.onclick = jsddm_close;			
				
				$(document).ready(function(){
							   
		   $("a").css({
			'text-decoration':'none',
		   });
		   $("a").hover(function () {
				$(this).css({'text-decoration':'none','font-weight':'bold'});
			  }, function () {
				var cssObj = {
				  'text-decoration':'none',
				  'font-weight':''
				}
				$(this).css(cssObj);
			  });
									   
		   $("#submit").css({
				'background-color':'white',
				'color':'#2F2825'
			});
			$("#submit").hover(function () {
				$(this).css({'background-color' : '#993333','color':'white','font-weight':'bold'});
			  }, function () {
				var cssObj = {
				  'background-color' : 'white',
				  'color' : '#2F2825',
				  'font-weight':''
				}
				$(this).css(cssObj);
			  });				  
				 
		 });
			</script>
			</head>
	
			<body>
			<!-- start header -->
			<div id="header">
				<div id="logo">
					<h1><span>UPLB</span> &nbsp; Leave Application</h1><br/>
					<ul id="jsddm">
						<?php if(isset($_SESSION['login']) && $_SESSION['login']==true) {?>
						<li><a href="#">ACTIONS <span>&#x25BC</span></a>
							<ul>
								<li><a href="AddEmployee.php">Add Employee</a></li>
								<li><a href="searchEmployee.php">Change Employee</a></li>
							</ul>
						</li>
						<li><a href="logout.php">LOG OUT</a>
						</li>
						<?php } ?>
					</ul>
				</div>
			</div>
			<!-- end header -->
			<div id="wrapper">
				<!-- start page -->
				<div id="pageEdit">
				<div id="page-bgEdit">					
				<!-- start content -->
					<div class='leaveData'>
					<?php LeaveFormView :: getEmployeeData($employeeNumber); ?>				
					</div>
					<div id="content">
					<div class="post">						
						<?php
								$flag = 0;								
								while ($data = mysql_fetch_assoc($r1)) {
								
									if ($flag == 0) {
										echo "
											<form class='leaveTable' name='leaveData' method='post' action='validateEdit.php'>
											<center>
											<table class='black'>
											<tr>
												<td colspan='6'>&nbsp;</td>
												<td>Leave Number&nbsp;&nbsp;<br /><font size='1'>&nbsp;&nbsp;</font></td>
												<td>Date of Filing<br/><font size='1'>(mm/dd/yyyy)</font></td>
												<td>Date Received<br/><font size='1'>(mm/dd/yyyy)</font></td>
												<td>Type of Leave<br /><font size='1'>&nbsp;&nbsp;</font></td>
												<td>Days<br /><font size='1'>&nbsp;&nbsp;</font></td>
												<td>Start Date<br/><font size='1'>(mm/dd/yyyy)</font></td>
												<td>End Date<br/><font size='1'>(mm/dd/yyyy)</font></td>
												<td>Status<br /><font size='1'>&nbsp;&nbsp;</font></td>
											</tr>";
										  $flag = 1;
									}
									$excess = $data['Excess'];
									$leaveNum = $data['Leave_number'];
									if ($data['Date_of_filing'] != NULL) {
										$dFiling = substr($data['Date_of_filing'], 5, 2)."/"
											   .substr($data['Date_of_filing'], 8,2)
											   ."/".substr($data['Date_of_filing'], 0,4);
									} else $dFiling = "";
									if ($data['Date_received'] != NULL) {
										$dReceived = substr($data['Date_received'], 5, 2)."/"
												 .substr($data['Date_received'], 8,2)
												 ."/".substr($data['Date_received'], 0,4);
									} else $dReceived = "";
									$startD = substr($data['Start_date'], 5, 2)."/"
											  .substr($data['Start_date'], 8,2)
											  ."/".substr($data['Start_date'], 0,4);
									$endD = substr($data['End_date'], 5, 2)."/"
											.substr($data['End_date'], 8,2)."/"
											.substr($data['End_date'], 0,4);
									$time = $data['Hours_minutes'];
																		
									echo "<tr><td colspan='6'>&nbsp;</td>";
									echo "<td>".$leaveNum."</td>";
									echo "<td><input type='text' name='dateOfFiling"
										 .$ctr."' id='dateOfFiling" 
										 .$ctr."' value='".$dFiling."' size=6 maxlength=10></td>";
									echo "<td><input type='text' name='dateReceived"
										 .$ctr."' id='dateReceived"
										 .$ctr."' value='".$dReceived."' size=6 maxlength=10></td>";
									
									echo "<td><select name='typeOfLeave".$ctr
										 ."' id='typeOfLeave".$ctr."' onChange='undertimeIsSelected(".$ctr.")'>";
									if($data['Type_of_leave']=='SICK_LEAVE'){
										echo "<option name='SICK_LEAVE' value='SICK_LEAVE'   selected>Sick Leave</option>";
									} else {echo "<option name='SICK_LEAVE' value='SICK_LEAVE'  >Sick Leave</option>";} 
									if($data['Type_of_leave']=='VACATION_LEAVE'){
										echo "<option name='VACATION_LEAVE' value='VACATION_LEAVE'   selected>Vacation Leave</option>";
									} else { echo "<option name='VACATION_LEAVE' value='VACATION_LEAVE'  >Vacation Leave</option>";}
									if($data['Type_of_leave']=='AWOL'){
										echo "<option name='AWOL' value='AWOL'   selected>Absence Without Leave</option>";
									} else { echo "<option name='AWOL' value='AWOL'  >Absence Without Leave</option>";}
									if($data['Type_of_leave']=='COMPENSATORY'){
										echo "<option name='COMPENSATORY' value='COMPENSATORY'   selected>Compensatory</option>";
									} else { echo "<option name='COMPENSATORY' value='COMPENSATORY'  >Compensatory</option>";}
									if($data['Type_of_leave']=='FORCED'){
										echo "<option name='FORCED' value='FORCED'   selected>Forced</option>";
									} else { echo "<option name='FORCED' value='FORCED'  >Forced</option>";}
									if($data['Type_of_leave']=='MONET_SL'){
										echo "<option name='MONET_SL' value='MONET_SL'   selected>Monetization(SL)</option>";
									} else { echo "<option name='MONET_SL' value='MONET_SL'  >Monetization(SL)</option>";}
									if($data['Type_of_leave']=='MONET_VL'){
										echo "<option name='MONET_VL' value='MONET_VL'   selected>Monetization(VL)</option>";
									} else { echo "<option name='MONET_VL' value='MONET_VL'  >Monetization(VL)</option>";}
									if($data['Type_of_leave']=='PARENTAL'){
										echo "<option name='PARENTAL' value='PARENTAL'   selected>Parental</option>";
									} else { echo "<option name='PARENTAL' value='PARENTAL'  >Parental</option>";}
									if($data['Type_of_leave']=='REHABILITATION'){
										echo "<option name='REHABILITATION' value='REHABILITATION'   selected>Rehabilitation</option>";
									} else { echo "<option name='REHABILITATION' value='REHABILITATION'  >Rehabilitation</option>";}
									if($data['Type_of_leave']=='RE-ENERGIZING'){
										echo "<option name='RE-ENERGIZING' value='RE-ENERGIZING'   selected>Re-energizing</option>";
									} else { echo "<option name='RE-ENERGIZING' value='RE-ENERGIZING'  >Re-energizing</option>";}
									if($data['Type_of_leave']=='SPECIAL'){
										echo "<option name='SPECIAL' value='SPECIAL'   selected>Special</option>";
									} else { echo "<option name='SPECIAL' value='SPECIAL'  >Special</option>";}
									if($data['Type_of_leave']=='SUSPENSION'){
										echo "<option name='SUSPENSION' value='SUSPENSION'   selected>Suspension</option>";
									} else { echo "<option name='SUSPENSION' value='SUSPENSION'  >Suspension</option>";}
									if($data['Type_of_leave']=='TARDINESS'){
										echo "<option name='TARDINESS' value='TARDINESS'   selected>Tardiness</option>";
									} else { echo "<option name='TARDINESS' value='TARDINESS'  >Tardiness</option>";}
									if($data['Type_of_leave']=='UNDERTIME'){
										echo "<option name='UNDERTIME' value='UNDERTIME'   selected>Undertime</option>";
									} else { echo "<option name='UNDERTIME' value='UNDERTIME'  >Undertime</option>";}
									if($gender=='Female'){
										if($data['Type_of_leave']=='MATERNAL'){
											echo "<option name='MATERNAL' value='MATERNAL'   selected>Maternal</option>";
										} else { echo "<option name='MATERNAL' value='MATERNAL'  >Maternal</option>";}
									} else{
										if($data['Type_of_leave']=='PATERNAL'){
											echo "<option name='PATERNAL' value='PATERNAL'   selected>Paternal</option>";
										} else { echo "<option name='PATERNAL' value='PATERNAL'  >Paternal</option>";}
									}			

									echo "</select></td>";
									
									echo "<td><input type='text' name='days".$ctr
										  ."' id='days".$ctr."' value='"
										  .$data['Days']."' size='1'></td>";
										  
									echo "<td><input type='text' name='startDate".$ctr
										  ."' id='startDate".$ctr."' value='"
										  .$startD."' size=6 maxlength=10></td>";
									
									echo "<td><input type='text' name='endDate".$ctr
										 ."' id='endDate".$ctr
										 ."' value='".$endD."' size=6 maxlength=10></td>";
									
									echo "<td><select name='status".$ctr."' id='status"
										 .$ctr."'>";
									
									if($excess==0){
										echo "<option name='WITH_PAY' value='WITH_PAY' selected>
												Approved With Pay</option>
											  <option name='WITHOUT_PAY' value= 'WITHOUT_PAY'>
												Approved Without Pay</option>";
									}else if($excess>0){
										echo "<option name='WITH_PAY' value='WITH_PAY'>
												Approved With Pay</option>
											  <option name='WITHOUT_PAY' value='WITHOUT_PAY' selected>
												Approved Without Pay</option>";
									}
									echo "</select></td>";
									echo "</tr>";
									echo "<tr><td >&nbsp;</td>
										  <td>&nbsp;</td>
										  <td><input type='hidden' name='employeeNumber' id='employeeNumber' value=".$employeeNumber."></td>";
									echo "<td><input type='hidden' name='time".$ctr."' 
										   id='time".$ctr."' value=".$time."></td>";
									echo "<td><input type='hidden' name='totalRows' id ='totalRows' value='".(intval($ctr)+1)."'/></td>";
									echo "<td><input type='hidden' name='leaveNum".$ctr."' id='leaveNum".$ctr."' value='".$leaveNum."'/></td>";									
									echo "</tr>";
									$ctr++;
								}
								echo "</table>
								</center><br/><div style='padding-left: 40px'><input type='submit' name='submitEditLeave' id='submit' value='Save Changes'/></div></form>";								
								?>		
							<center>
							<p class="links"><a href='menu.php' class="more">&laquo;&laquo;&nbsp;&nbsp;Home&nbsp;&nbsp;&raquo;&raquo;</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='startAdd.php' class="more">&laquo;&laquo;&nbsp;&nbsp;Add Leave&nbsp;&nbsp;&raquo;&raquo;</a></p>
							</center>
					</div> <!-- post -->
				</div> <!-- end content -->
				<div style="clear: both;">&nbsp;</div>
			</div>
			</div><!-- end page -->
		</div>
		<div id="footerEdit">
		</div>		
		</body></html>
	<?php	
		//HERE
		
		if ($ctr == 0) {
			echo "Database empty.";
		}
		return 1;
	}
	
	public function requestEditLeave($employeeNumber) {
		$link = makeSQLconnection();	
		$rowCtr = 0;
		$array = array();
		$index = 0;
		$data = LeaveManager :: getLeaveData($employeeNumber, "load");
		$temp = "endDate".$rowCtr;
		$endDate = $_POST[$temp];
		$result = "";
		
	
		$endMonth=substr($endDate, 0, 2);
		$endDay=substr($endDate, 3, 2);
		$endYear=substr($endDate, 6, 4);
		
	
		while ($pData=mysql_fetch_assoc($data)) {	
			if($_SESSION['valid'] == true) {
				$i = $rowCtr;
				$leaveNum = $pData['Leave_number'];
					
				$dF = 'dateOfFiling'.$i;					
				$dF2 = $_SESSION[$dF];
				$dR = 'dateReceived'.$i;
				$dR2 = $_SESSION[$dR];
				$tL = 'typeOfLeave'.$i;
				$tL2 = $_SESSION[$tL];
				$d = 'days'.$i;
				$d2 = $_SESSION[$d];					
				$sD = 'startDate'.$i;
				$sD2 = $_SESSION[$sD];
				$eD = 'endDate'.$i;
				$eD2 = $_SESSION[$eD];
				$s = 'status'.$i;
				$s2 = $_SESSION[$s];
				$t = 'time'.$i;
				$t2 = $_SESSION[$t];
			}
			//access database if the data in DB change
			
			if ($rowCtr > 0) {
				
				$temp2 = "startDate".$rowCtr;
				$startDate = $_POST[$temp2];
				
				$startMonth=substr($startDate, 0, 2);
				$startDay=substr($startDate, 3, 2);
				$startYear=substr($startDate, 6, 4);
				
				if ($startYear < $endYear) {
					$array[$index] = $pData['Leave_number'];
					$index++;
				}else if($startYear == $endYear){
					if ($startMonth < $endMonth) {
						$array[$index] = $pData['Leave_number'];
						$index++;							
					}else if($startMonth == $endMonth){
						if ($startDay <= $endDay) {
							$array[$index] = $pData['Leave_number'];
							$index++;
						}
					}
				}
				
				$temp = "endDate".$rowCtr;
				$endDate = $_POST[$temp];
				$endYear=substr($endDate, 6, 4);
				$endMonth=substr($endDate, 0, 2);
				$endDay=substr($endDate, 3, 2);
			}
			if ($index == 0) {
				$result += LeaveFormController :: editLeaveForm($leaveNum, $dF2, $dR2, $tL2,
											$d2, $sD2, $eD2, $s2, $t2, $employeeNumber);
			}
			$rowCtr++;
		}
		if ($index > 0) {
			echo "Conflict on the dates in leave number(s) ";
			for ($i = 0; $i < $index; $i++) {
				echo $array[$i] ." ";
			}
			echo ". <br />";
		} else{
			if ($result == $rowCtr) LeaveFormView::showMessage(2);
			else LeaveFormView::showMessage(3);
		}
		mysql_close($link);
		return 1;
	}
	
	public function getEmployeeData($employeeNumber) {
		if (LeaveManager :: getLeaveData($employeeNumber, "load")) {
			LeaveFormController::computeLeaveBalance($employeeNumber);
		}	
		return 1;
	}
	
	public function displayLeaveReport($employeeNumber)
	{
		$flag = 0;
		$accumulatedSickDays = 0;
		$accumulatedVacDays = 0;
		$accumulatedSpecial = 0;
		$accumulatedPaternal = 0;
		$accumulatedMaternal = 0;
		$accumulatedReEnergizing = 0;
		$accumulatedMonetization = 0;
		$accumulatedVacWo = 0;
		$accumulatedSicWo = 0;
		$accumulatedForced = 0;
		$accumulatedUndertime = 0;
		$accumulatedTardiness = 0;
		$accumulatedExcessSpecial = 0;
		$leaveNumber = "";
		$leaveType = "";
		$dateOfFiling = "";
		$day = "";
		$startdate = "";
		$enddate = "";
		$status = "";
		$earn = "";
		$VLbal = "";
		$SLbal = "";
		$leavetotal = "";

		$empData = LeaveManager::getEmployeeData($employeeNumber);
		
		while($data = mysql_fetch_assoc($empData)){
			$_SESSION['fName'] = $data['First_name'];
			$_SESSION['mName'] = $data['Middle_name'];
			$_SESSION['lName'] = $data['Last_name'];
			$_SESSION['gender'] = $data['Employee_gender'];
			$_SESSION['dept'] = $data['Employee_department'];
		}

		$r1 = LeaveManager::getLeaveData($employeeNumber, "load");
		
		if (mysql_num_rows($r1) > 0) {
			while($data = mysql_fetch_assoc($r1)){
				$leaveType = $leaveType.$data['Type_of_leave']."/";
				$day = $day.$data['Days']."/";
				if ($data['Type_of_leave'] == "SICK_LEAVE") {
					if($data['Status'] == "WITH_PAY") {
						$sickLeave = $data['Days'];
						$accumulatedSickDays += $sickLeave;
					} else {
						$sickLeaveWithout = $data['Days'];
						$accumulatedSicWo += $sickLeaveWithout;
					}
				} else if ($data['Type_of_leave'] == "VACATION_LEAVE"){
					if($data['Status'] == "WITH_PAY") {
						$vacationLeave = $data['Days'];
						$accumulatedVacDays += $vacationLeave;
					} else {
						$vacationLeaveWithout = $data['Days'];
						$accumulatedVacWo += $vacationLeaveWithout;
					}
																
				} else if ($data['Type_of_leave'] == "SPECIAL"){
					$specialLeave = $data['Days'];
					$accumulatedSpecial += $specialLeave;											
				} else if ($data['Type_of_leave'] == "MATERNAL"){
					$maternalLeave = $data['Days'];
					$accumulatedMaternal += $maternalLeave;											
				} else if ($data['Type_of_leave'] == "PATERNAL"){
					$paternalLeave = $data['Days'];
					$accumulatedPaternal += $paternalLeave;											
				} else if ($data['Type_of_leave'] == "RE-ENERGIZING") {
					$reenergizingLeave = $data['Days'];
					$accumulatedReEnergizing += $reenergizingLeave;
				}
				else if ($data['Type_of_leave'] == "MONET_SL" || $data['Type_of_leave'] == "MONET_VL") {
					$monetLeave = $data['Days'];
					$accumulatedMonetization += $monetLeave;
				} else if ($data['Type_of_leave'] == "FORCED") {
					$forcedLeave = $data['Days'];
					$accumulatedForced += $forcedLeave;
				} else if ($data['Type_of_leave'] == "TARDINESS") {
					$tardiLeave = $data['Days'];
					$accumulatedTardiness += $tardiLeave;
				} else if ($data['Type_of_leave'] == "UNDERTIME") {
					$underLeave = $data['Days'];
					$accumulatedUndertime += $underLeave;
				}
				
				$_SESSION['accumulatedSickDays'] = $accumulatedSickDays;
				$_SESSION['accumulatedVacDays'] = $accumulatedVacDays;
				$_SESSION['accumulatedSpecial'] = $accumulatedSpecial;
				$_SESSION['accumulatedPaternal'] = $accumulatedPaternal;
				$_SESSION['accumulatedMaternal'] = $accumulatedMaternal;
				$_SESSION['accumulatedReEnergizing'] = $accumulatedReEnergizing;
				$_SESSION['accumulatedMonetization'] = $accumulatedMonetization;
				$_SESSION['accumulatedVacWo'] = $accumulatedVacWo;
				$_SESSION['accumulatedSicWo'] = $accumulatedSicWo;
				$_SESSION['accumulatedForced'] = $accumulatedForced;
				$_SESSION['accumulatedUndertime'] = $accumulatedUndertime;
				$_SESSION['accumulatedTardiness'] = $accumulatedTardiness;
				if($accumulatedSpecial > 6)
				{
					$accumulatedExcessSpecial = $accumulatedSpecial - 6;
				}
				$_SESSION['accumulatedExcessSpecial'] = $accumulatedExcessSpecial;
				
				$leaveNumber = $leaveNumber.$data['Leave_number']."/";
			
				if ($data['Date_of_filing'] != NULL) {
					$newDOF = substr($data['Date_of_filing'], 5, 2)."/"
							 .substr($data['Date_of_filing'], 8,2)
							 ."/".substr($data['Date_of_filing'], 0,4);
				} else $newDOF = ' ';
				
				$dateOfFiling = $dateOfFiling.$newDOF."/";

				$startdate = $startdate.$data['Start_date']."/";
				$enddate = $enddate.$data['End_date']."/";
				$status = $status.$data['Status']."/";
				
				$balance = LeaveFormController::computeRowBalance($data['Leave_number'], $employeeNumber, $accumulatedSickDays, $accumulatedVacDays);
				$array=explode('/',$balance);
				$sickLeaveBalance=$array[0];
				$vacationLeaveBalance=$array[1];
				$tempBalance=$array[2];
				$total = $sickLeaveBalance+$vacationLeaveBalance;
				
				$earn = $earn.$tempBalance."/";
				$VLbal = $VLbal.$vacationLeaveBalance."/";
				$SLbal = $SLbal.$sickLeaveBalance."/";
				$leavetotal = $leavetotal.$total."/";
			}
			
			$_SESSION['leaveNumber'] = $leaveNumber;
			$_SESSION['dateOfFiling'] = $dateOfFiling;
			$_SESSION['leaveType'] = $leaveType;
			$_SESSION['day'] = $day;
			$_SESSION['startdate'] = $startdate;
			$_SESSION['enddate'] = $enddate;
			$_SESSION['status'] = $status;
			$_SESSION['earn'] = $earn;
			$_SESSION['VLbal'] = $VLbal;
			$_SESSION['SLbal'] = $SLbal;
			$_SESSION['leavetotal'] = $leavetotal;
			
			ob_clean();
			header("Location: viewPDFVersion.php");
		}
			
			
	}
	
}
?>